//=============================================================================
#include "CApp.h"

//=============================================================================
bool CApp::OnInit() {
    //--------------------------------------------------------------------------
    // SDL
    //--------------------------------------------------------------------------
    if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
        return false;
    }

    freopen("CON", "w", stdout);
    freopen("CON", "w", stderr);

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE,    16);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,  16);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,   16);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,  16);

    SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,    16);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,  16);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,   16);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,  16);

    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,  1);

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    if((Surf_Display = SDL_SetVideoMode(WWIDTH, WHEIGHT, WBITS, WFLAGS)) == NULL) {
        printf("Unable to set video mode");
        return false;
    }

    SDL_WM_SetCaption(WCAPTION, WCAPTION);

    //--------------------------------------------------------------------------
    // OpenGL
    //--------------------------------------------------------------------------
    glShadeModel(GL_SMOOTH);
    glClearColor(19.0f, 130.0f, 215.0f, 255.0f);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    glViewport(0, 0, WWIDTH, WHEIGHT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glOrtho(0, WWIDTH, WHEIGHT, 0, 500, -500);

    glMatrixMode(GL_MODELVIEW);

    glEnable(GL_TEXTURE_2D);

    glLoadIdentity();

    //--------------------------------------------------------------------------
    // Misc
    //--------------------------------------------------------------------------
    //if(CFontEngine::FontControl.OnInit() == false) {
    //    return false;
   // }

    return true;
}

//=============================================================================
